package handel

import (
	"github.com/gin-gonic/gin"
	"role-guard/model"
	"role-guard/pkg"
)

func Login(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")

	if username == "" || password == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不可为空",
		})
		return
	}
	user := model.UserList{
		Username: username,
		Password: pkg.Md5Str(password),
	}
	err := model.DB.Create(&user).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "登录失败",
		})
		return
	} else {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "登录成功",
		})
		return
	}

}
func Info(c *gin.Context) {

}
func Bang(c *gin.Context) {
}
func List(c *gin.Context) {
	var ben []model.Ben
	model.DB.Find(&ben)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": ben,
	})
	return
}
